package ems_lib

import (
	"fmt"
	"strconv"
)

type Value interface {
	To_bool() bool
	To_int8() int8
	To_uint8() uint8
	To_int16() int16
	To_uint16() uint16
	To_int32() int32
	To_uint32() uint32
	To_int64() int64
	To_uint64() uint64
	To_flaot32() float32
	To_flaot64() float64
	To_string() string
}

type Type_bit bool
type Type_i8 int8
type Type_iu8 uint8
type Type_i16 int16
type Type_iu16 uint16
type Type_i32 int32
type Type_iu32 uint32
type Type_i64 int64
type Type_iu64 uint64
type Type_float float32
type Type_double float64
type Type_string string

// 入参为bool
func (u Type_bit) to_bit() bool {
	return bool(u)
}
func (u Type_bit) to_i8() int8 {
	var val int8
	if u {
		val = 1
	}
	return val
}
func (u Type_bit) to_iu8() uint8 {
	var val uint8
	if u {
		val = 1
	}
	return val
}
func (u Type_bit) To_int16() int16 {
	var val int16
	if u {
		val = 1
	}
	return val
}
func (u Type_bit) To_uint16() uint16 {
	var val uint16
	if u {
		val = 1
	}
	return val
}

func (u Type_bit) To_int32() int32 {
	var val int32
	if u {
		val = 1
	}
	return val
}
func (u Type_bit) To_uint32() uint32 {
	var val uint32
	if u {
		val = 1
	}
	return val
}

func (u Type_bit) To_int64() int64 {
	var val int64
	if u {
		val = 1
	}
	return val
}
func (u Type_bit) To_uint64() int64 {
	var val int64
	if u {
		val = 1
	}
	return val
}
func (u Type_bit) To_flaot32() float32 {
	var val float32
	if u {
		val = 1
	}
	return val
}
func (u Type_bit) To_flaot64() float64 {
	var val float64
	if u {
		val = 1
	}
	return val
}
func (u Type_bit) To_string() string {
	var val string
	if u {
		val = "1"
	}
	return val
}

// 入参为int8
func (u Type_i8) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_i8) To_int8() int8 {
	return int8(u)
}
func (u Type_i8) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_i8) To_int16() int16 {
	return int16(u)
}
func (u Type_i8) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_i8) To_int32() int32 {
	return int32(u)
}
func (u Type_i8) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_i8) To_int64() int64 {
	return int64(u)
}
func (u Type_i8) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_i8) To_flaot32() float32 {
	return float32(u)
}
func (u Type_i8) To_flaot64() float64 {
	return float64(u)
}
func (u Type_i8) To_string() string {
	return strconv.FormatInt(int64(u), 10)
}

// 入参为uint8
func (u Type_iu8) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_iu8) To_int8() int8 {
	return int8(u)
}
func (u Type_iu8) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_iu8) To_int16() int16 {
	return int16(u)
}
func (u Type_iu8) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_iu8) To_int32() int32 {
	return int32(u)
}
func (u Type_iu8) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_iu8) To_int64() int64 {
	return int64(u)
}
func (u Type_iu8) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_iu8) To_flaot32() float32 {
	return float32(u)
}
func (u Type_iu8) To_flaot64() float64 {
	return float64(u)
}
func (u Type_iu8) To_string() string {
	return string(u)
}

// /////////////////////////////////////////////////////////////////////////////////////////
// 入参为int16
func (u Type_i16) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_i16) To_int8() int8 {
	return int8(u)
}
func (u Type_i16) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_i16) To_int16() int16 {
	return int16(u)
}
func (u Type_i16) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_i16) To_int32() int32 {
	return int32(u)
}
func (u Type_i16) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_i16) To_int64() int64 {
	return int64(u)
}
func (u Type_i16) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_i16) To_flaot32() float32 {
	return float32(u)
}
func (u Type_i16) To_flaot64() float64 {
	return float64(u)
}
func (u Type_i16) To_string() string {
	return strconv.FormatInt(int64(u), 10)
}

// 入参为uint16
func (u Type_iu16) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_iu16) To_int8() int8 {
	return int8(u)
}
func (u Type_iu16) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_iu16) To_int16() int16 {
	return int16(u)
}
func (u Type_iu16) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_iu16) To_int32() int32 {
	return int32(u)
}
func (u Type_iu16) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_iu16) To_int64() int64 {
	return int64(u)
}
func (u Type_iu16) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_iu16) To_flaot32() float32 {
	return float32(u)
}
func (u Type_iu16) To_flaot64() float64 {
	return float64(u)
}
func (u Type_iu16) To_string() string {
	return strconv.FormatInt(int64(u), 10)
}

// 入参为int32
func (u Type_i32) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_i32) To_int8() int8 {
	return int8(u)
}
func (u Type_i32) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_i32) To_int16() int16 {
	return int16(u)
}
func (u Type_i32) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_i32) To_int32() int32 {
	return int32(u)
}
func (u Type_i32) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_i32) To_int64() int64 {
	return int64(u)
}
func (u Type_i32) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_i32) To_flaot32() float32 {
	return float32(u)
}
func (u Type_i32) To_flaot64() float64 {
	return float64(u)
}
func (u Type_i32) To_string() string {
	return string(u)
}

// 入参为uint32
func (u Type_iu32) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_iu32) To_int8() int8 {
	return int8(u)
}
func (u Type_iu32) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_iu32) To_int16() int16 {
	return int16(u)
}
func (u Type_iu32) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_iu32) To_int32() int32 {
	return int32(u)
}
func (u Type_iu32) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_iu32) To_int64() int64 {
	return int64(u)
}
func (u Type_iu32) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_iu32) To_flaot32() float32 {
	return float32(u)
}
func (u Type_iu32) To_flaot64() float64 {
	return float64(u)
}
func (u Type_iu32) To_string() string {
	return strconv.FormatInt(int64(u), 10)
}

// 入参为int64
func (u Type_i64) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_i64) To_int8() int8 {
	return int8(u)
}
func (u Type_i64) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_i64) To_int16() int16 {
	return int16(u)
}
func (u Type_i64) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_i64) To_int32() int32 {
	return int32(u)
}
func (u Type_i64) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_i64) To_int64() int64 {
	return int64(u)
}
func (u Type_i64) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_i64) To_flaot32() float32 {
	return float32(u)
}
func (u Type_i64) To_flaot64() float64 {
	return float64(u)
}
func (u Type_i64) To_string() string {
	return strconv.FormatInt(int64(u), 10)
}

// 入参为uint64
func (u Type_iu64) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_iu64) To_int8() int8 {
	return int8(u)
}
func (u Type_iu64) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_iu64) To_int16() int16 {
	return int16(u)
}
func (u Type_iu64) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_iu64) To_int32() int32 {
	return int32(u)
}
func (u Type_iu64) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_iu64) To_int64() int64 {
	return int64(u)
}
func (u Type_iu64) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_iu64) To_flaot32() float32 {
	return float32(u)
}
func (u Type_iu64) To_flaot64() float64 {
	return float64(u)
}
func (u Type_iu64) To_string() string {
	return strconv.FormatInt(int64(u), 10)
}

// 入参为float
func (u Type_float) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_float) To_int8() int8 {
	return int8(u)
}
func (u Type_float) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_float) To_int16() int16 {
	return int16(u)
}
func (u Type_float) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_float) To_int32() int32 {
	return int32(u)
}
func (u Type_float) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_float) To_int64() int64 {
	return int64(u)
}
func (u Type_float) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_float) To_flaot32() float32 {
	return float32(u)
}
func (u Type_float) To_flaot64() float64 {
	return float64(u)
}
func (u Type_float) To_string() string {
	return fmt.Sprintf("%f", u)
}

// 入参为double
func (u Type_double) To_bool() bool {
	var val bool
	if u != 0 {
		val = true
	}
	return val
}
func (u Type_double) To_int8() int8 {
	return int8(u)
}
func (u Type_double) To_uint8() uint8 {
	return uint8(u)
}

func (u Type_double) To_int16() int16 {
	return int16(u)
}
func (u Type_double) To_uint16() uint16 {
	return uint16(u)
}

func (u Type_double) To_int32() int32 {
	return int32(u)
}
func (u Type_double) To_uint32() uint32 {
	return uint32(u)
}

func (u Type_double) To_int64() int64 {
	return int64(u)
}
func (u Type_double) To_uint64() uint64 {
	return uint64(u)
}

func (u Type_double) To_flaot32() float32 {
	return float32(u)
}
func (u Type_double) To_flaot64() float64 {
	return float64(u)
}
func (u Type_double) To_string() string {
	return fmt.Sprintf("%f", u)
}

// 入参为string
func (u Type_string) To_bool() bool {
	var val bool
	val, _ = strconv.ParseBool(string(u))
	return val
}
func (u Type_string) To_int8() int8 {
	var val int64
	val, _ = strconv.ParseInt(string(u), 0, 8)
	return int8(val)
}
func (u Type_string) To_uint8() uint8 {
	var val int64
	val, _ = strconv.ParseInt(string(u), 0, 8)
	return uint8(val)
}

func (u Type_string) To_int16() int16 {
	var val int64
	val, _ = strconv.ParseInt(string(u), 0, 16)
	return int16(val)
}
func (u Type_string) To_uint16() uint16 {
	var val int64
	val, _ = strconv.ParseInt(string(u), 0, 16)
	return uint16(val)
}

func (u Type_string) To_int32() int32 {
	var val int64
	val, _ = strconv.ParseInt(string(u), 0, 32)
	return int32(val)
}
func (u Type_string) To_uint32() uint32 {
	var val int64
	val, _ = strconv.ParseInt(string(u), 0, 32)
	return uint32(val)
}

func (u Type_string) To_int64() int64 {
	var val int64
	val, _ = strconv.ParseInt(string(u), 0, 64)
	return val
}
func (u Type_string) To_uint64() uint64 {
	var val int64
	val, _ = strconv.ParseInt(string(u), 0, 64)
	return uint64(val)
}

func (u Type_string) To_flaot32() float32 {
	var val float64
	val, _ = strconv.ParseFloat(string(u), 32)
	return float32(val)
}
func (u Type_string) To_flaot64() float64 {
	var val float64
	val, _ = strconv.ParseFloat(string(u), 64)
	return val
}
func (u Type_string) To_string() string {
	return string(u)
}
